package com.example.xt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xt.entity.Medicine;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author ${author}
 * @since 2022-02-27
 */
@Mapper
public interface MedicineMapper extends BaseMapper<Medicine> {
    @Update("UPDATE medicine a INNER JOIN(SELECT id,DATEDIFF(CURDATE(),ex) m FROM medicine b) c on a.id=c.id set a.exp=c.m")
    void exp();

    @Select("SELECT id FROM medicine WHERE `name`=#{name} AND costprice=#{costprice} AND price =#{price} AND ep=#{ep} AND ex=#{ex} AND clas=#{clas} AND region=#{region} AND stock!=#{stock}")
    Integer addstock(String name, Integer costprice, Integer price, Integer ep, Date ex, Integer stock, String clas, String region);

    @Select("SELECT id FROM medicine WHERE `name`=#{name} AND costprice=#{costprice} AND price =#{price} AND ep=#{ep} AND ex=#{ex}")
    Integer or(String name, Integer costprice, Integer price, Integer ep, Date ex);

    @Update("UPDATE medicine set stock=stock+#{stock} WHERE id=#{id}")
    boolean orupdata(Integer stock, Object id);
}
